﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Text;

namespace Utility
{
   public class EnumUtil
    {
        /// <summary>
        /// 禁用状态枚举
        /// </summary>
        public enum DisableStatus
        {
            /// <summary>
            /// 禁用：1
            /// </summary>
            diable_true = 1,

            /// <summary>
            /// 启用：0，默认是启用
            /// </summary>
            disable_false = 0
        }

        /// <summary>
        /// 操作类型枚举
        /// </summary>
        public enum OperationEnum
        {
            /// <summary>
            /// 登录：1
            /// </summary>
            [Description("登录")]
            Login = 1,

            /// <summary>
            /// 登出：2,
            /// </summary>
            [Description("登出")]
            Logout = 2,

            /// <summary>
            /// 新增：3,
            /// </summary>
            [Description("新增")]
            add = 3,

            /// <summary>
            /// 修改：4,
            /// </summary>
            [Description("修改")]
            update = 4,

            /// <summary>
            /// 查询：5,
            /// </summary>
            [Description("查询")]
            select = 5,

            /// <summary>
            /// 删除：6,
            /// </summary>
            [Description("删除")]
            delete = 6,

            /// <summary>
            /// 上传：7,
            /// </summary>
            [Description("上传")]
            upload = 7,

            /// <summary>
            /// 下载：8,
            /// </summary>
            [Description("下载")]
            download = 8,

            /// <summary>
            /// 审核：9,
            /// </summary>
            [Description("审核")]
            success = 9,

            /// <summary>
            /// 驳回：10,
            /// </summary>
            [Description("驳回")]
            back = 9
        }

        public static String GetOperationEnumDesc(OperationEnum e)
        {
            FieldInfo EnumInfo = e.GetType().GetField(e.ToString());
            DescriptionAttribute[] EnumAttributes = (DescriptionAttribute[])EnumInfo.
                GetCustomAttributes(typeof(DescriptionAttribute), false);
            if (EnumAttributes.Length > 0)
            {
                return EnumAttributes[0].Description;
            }
            return e.ToString();
        }

    }
    
   public class EnumUtilHelp<EnumModel>
    {
        //根据枚举的int值取出string值
        protected string GetEnunValue(int key, EnumModel model)
        {
            EnumModel call = (EnumModel)Enum.Parse(typeof(EnumModel), key.ToString());
            return call.ToString();
        }
        //根据枚举的string值取出int值
        protected int GetEnunKey(string value, EnumModel model)
        {
            return (int)Enum.Parse(typeof(EnumModel), value);
        }
    }
}
